package com.pug.zixun.controller.questionscategory;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pug.zixun.service.questionscategory.IQuestionsCategoryService;
import com.pug.zixun.pojo.QuestionsCategory;
import com.pug.zixun.vo.QuestionsCategoryVo;
import com.pug.zixun.bo.QuestionsCategoryBo;
import com.pug.zixun.commons.enums.ResultStatusEnum;
import com.pug.zixun.commons.ex.PugValidatorException;
import com.pug.zixun.commons.utils.fn.asserts.Vsserts;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import com.pug.zixun.controller.BaseController;
import java.util.List;
import org.pug.generator.anno.PugDoc;
/**
 * QuestionsCategoryController
 * 创建人:yykk<br/>
 * 时间：2022-08-09 22:12:35 <br/>
 * 源码下载：前台代码 git clone https://gitee.com/kekesam/kuangstudy-pug-ui.git
 * 飞哥B站地址：后台代码 git clone https://gitee.com/kekesam/kuangstudy-pug-parent.git
 * @version 1.0.0<br/>
 *
*/

@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="文章分类",tabname="kss_question_category")
public class QuestionsCategoryController extends BaseController{

    private final IQuestionsCategoryService questionscategoryService;


    /**
     * 查询文章分类列表信息
     * @path : /admin/questionscategory/list
     * @method: findQuestionsCategorys
     * @result : List<QuestionsCategoryBo>
     * 创建人:yykk
     * 创建时间：2022-08-09 22:12:35
     * @version 1.0.0
     * @return
     */
    @PostMapping("/questionscategory/list")
    @PugDoc(name="查询文章分类列表信息")
    public List<QuestionsCategoryBo> findQuestionsCategoryList() {
        return questionscategoryService.findQuestionsCategoryList();
    }

	/**
	 * 查询文章分类列表信息并分页
	 * @path : /admin/questionscategory/load
     * @method: findQuestionsCategorys
     * @param : questionscategoryVo
     * @result : IPage<QuestionsCategoryBo>
	 * 创建人:yykk
	 * 创建时间：2022-08-09 22:12:35
	 * @version 1.0.0
	*/
    @PostMapping("/questionscategory/load")
    @PugDoc(name="查询文章分类列表信息并分页")
    public IPage<QuestionsCategoryBo> findQuestionsCategorys(@RequestBody QuestionsCategoryVo questionscategoryVo) {
        return questionscategoryService.findQuestionsCategoryPage(questionscategoryVo);
    }


    /**
     * 根据文章分类id查询明细信息
     * @method: get/{id}
     * @path : /admin/questionscategory/get/{id}
     * @param : id
     * @result : QuestionsCategoryBo
     * 创建人:yykk
     * 创建时间：2022-08-09 22:12:35
     * @version 1.0.0
    */
    @PostMapping("/questionscategory/get/{id}")
    @PugDoc(name="根据文章分类id查询明细信息")
    public QuestionsCategoryBo getQuestionsCategoryById(@PathVariable("id") String id) {
        if(Vsserts.isEmpty(id)){
           throw new PugValidatorException(ResultStatusEnum.ID_NOT_EMPTY);
        }
        return questionscategoryService.getQuestionsCategoryById(new Long(id));
    }


	/**
	 * 保存和修改文章分类
     * @method: saveupdate
	 * @path : /admin/questionscategory/save
     * @param : questionscategory
     * @result : QuestionsCategoryBo
	 * 创建人:yykk
	 * 创建时间：2022-08-09 22:12:35
	 * @version 1.0.0
	*/
    @PostMapping("/questionscategory/saveupdate")
    @PugDoc(name="保存和修改文章分类")
    public QuestionsCategoryBo saveupdateQuestionsCategory(@RequestBody QuestionsCategory questionscategory) {
        return questionscategoryService.saveupdateQuestionsCategory(questionscategory);
    }


    /**
	 * 根据文章分类id删除文章分类
     * @method: delete/{id}
     * @path : /admin/questionscategory/delete/{id}
     * @param : id
     * @result : int
	 * 创建人:yykk
	 * 创建时间：2022-08-09 22:12:35
	 * @version 1.0.0
	*/
    @PostMapping("/questionscategory/delete/{id}")
    @PugDoc(name="根据文章分类id删除文章分类")
    public int deleteQuestionsCategoryById(@PathVariable("id") String id) {
        if(Vsserts.isEmpty(id)){
            throw new PugValidatorException(ResultStatusEnum.ID_NOT_EMPTY);
        }
        return questionscategoryService.deleteQuestionsCategoryById(new Long(id));
    }


   /**
   	 * 根据文章分类ids批量删除文章分类
     * @method: questionscategory/delBatch
     * @path : /admin/questionscategory/delBatch
     * @param : questionscategoryVo
     * @result : boolean
   	 * 创建人:yykk
   	 * 创建时间：2022-08-09 22:12:35
   	 * @version 1.0.0
   	*/
    @PostMapping("/questionscategory/delBatch")
    @PugDoc(name="根据文章分类ids批量删除文章分类")
    public boolean delQuestionsCategory(@RequestBody QuestionsCategoryVo questionscategoryVo) {
        log.info("你要批量删除的IDS是:{}", questionscategoryVo.getBatchIds());
        if (Vsserts.isEmpty(questionscategoryVo.getBatchIds())) {
            throw new PugValidatorException(ResultStatusEnum.ID_NOT_EMPTY);
        }
        return questionscategoryService.delBatchQuestionsCategory(questionscategoryVo.getBatchIds());
    }
}